Newbie has more is_null woes

Newbie has more is_null woes

am 04.08.2007 18:25:41 von Big Moxy

The while statement shows that the variable phrase is null. However
the if statements that follow return true because 3 table rows are
created on my page. I know that isset() is true for phrase however
given the display output I expect !is_null() to return false and
therefore leave the if construct. Can someone please tell me why this
is not happening?

value="^^no^^" name="logo" value="296.06" name="part_sell_price"
value="" name="phrase" value="script" name="font_type" value="386"
name="thread_color" value="^^no^^" name="nomex" value="Next >>"
name="Submit"

session_start();
foreach ($_POST as $key => $value) {
$_SESSION[$key] = $value;
}

while (list($name, $value) = each($HTTP_POST_VARS))
{
echo "value=\"$value\" name=\"$name\"\n";
}
?>


if (isset($_SESSION['phrase'])) {
if (!is_null($_SESSION['phrase'])) {
if ($_SESSION['phrase'] != "^^no^^") {
?>

Monogram Color: div>



Monogram:
td>
" >"


Font:

" >"

}
}
}
?>

Thank you!!
tim

Re: Newbie has more is_null woes

am 04.08.2007 18:54:27 von Big Moxy

On Aug 4, 10:25 am, Big Moxy wrote:
> The while statement shows that the variable phrase is null. However
> the if statements that follow return true because 3 table rows are
> created on my page. I know that isset() is true for phrase however
> given the display output I expect !is_null() to return false and
> therefore leave the if construct. Can someone please tell me why this
> is not happening?
>
> value="^^no^^" name="logo" value="296.06" name="part_sell_price"
> value="" name="phrase" value="script" name="font_type" value="386"
> name="thread_color" value="^^no^^" name="nomex" value="Next >>"
> name="Submit"
>
> > session_start();
> foreach ($_POST as $key => $value) {
> $_SESSION[$key] = $value;
>
> }
>
> while (list($name, $value) = each($HTTP_POST_VARS))
> {
> echo "value=\"$value\" name=\"$name\"\n";
> }
> ?>
>
> > if (isset($_SESSION['phrase'])) {
> if (!is_null($_SESSION['phrase'])) {
> if ($_SESSION['phrase'] != "^^no^^") {
> ?>
>
>

Monogram Color: > div>
>
>
>
>
Monogram:
> td>
> ""
>
>
>
>
Font:

> ""
>
>
> > }
> }
>
> ?>
>
> Thank you!!
> tim

How does empty() compare to the above? I found this at http://us3.php.net/empty
-
$var = 0;

// Evaluates to true because $var is empty
if (empty($var)) {
echo '$var is either 0, empty, or not set at all';
}

// Evaluates as true because $var is set
if (isset($var)) {
echo '$var is set even though it is empty';
}
?>

Re: Newbie has more is_null woes

am 04.08.2007 20:00:22 von luiheidsgoeroe

On Sat, 04 Aug 2007 18:54:27 +0200, Big Moxy wrote:
> How does empty() compare to the above? I found this at =

> http://us3.php.net/empty
> -
> > $var =3D 0;
>
> // Evaluates to true because $var is empty
> if (empty($var)) {
> echo '$var is either 0, empty, or not set at all';
> }
>
> // Evaluates as true because $var is set
> if (isset($var)) {
> echo '$var is set even though it is empty';
> }

Some copy.pasting from the manual for you:

empty() returns true for:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)

is_null() (hardly used, for good reason) returns true for:
NULL

isset()
Wether or not a variable is set, with one exception: isset() will retur=
n =

FALSE if testing a variable that has been set to NULL. Also note that a =
=

NULL byte ("\0") is not equivalent to the PHP NULL constant.

A variable is considered to be NULL if
- it has been assigned the constant NULL, or
- it has not been set to any value yet, or
- it has been unset (in which case offcourse isset() will also return =

false).


Of all these, a combination of "if(isset($var) && !empty($var)) //some =

code" is the most common.
-- =

Rik Wasmus

Re: Newbie has more is_null woes

am 04.08.2007 20:06:31 von luiheidsgoeroe

On Sat, 04 Aug 2007 18:25:41 +0200, Big Moxy wrote:

> The while statement shows that the variable phrase is null. However
> the if statements that follow return true because 3 table rows are
> created on my page.

> value=3D"^^no^^" name=3D"logo" value=3D"296.06" name=3D"part_sell_pric=
e"
> value=3D"" name=3D"phrase" value=3D"script" name=3D"font_type" value=3D=
"386"
> name=3D"thread_color" value=3D"^^no^^" name=3D"nomex" value=3D"Next >>=
"
> name=3D"Submit"
>
> > session_start();
> foreach ($_POST as $key =3D> $value) {
> $_SESSION[$key] =3D $value;
> }
>
> while (list($name, $value) =3D each($HTTP_POST_VARS))

please use the same construct as before (foreach($_POST as...)), as =

relying on $HTTP_POST_VARS is hopelessly outdated.

> {
> echo "value=3D\"$value\" name=3D\"$name\"\n";
> }

Which will show you nothing about the NULL status. NULL is a strange =

beast, an empty string ('') or false will also print nothing to your =

screen, doesn't mean it is NULL. All values arrived by a POST are a stri=
ng =

by default, and a string cannot be NULL, it can be empty though, not the=
=

same thing. NULL is actually a type of it's own (next to strings, =

booleans, integers, floats etc.).

-- =

Rik Wasmus

Re: Newbie has more is_null woes

am 04.08.2007 22:32:13 von Big Moxy

On Aug 4, 12:06 pm, Rik wrote:
> On Sat, 04 Aug 2007 18:25:41 +0200, Big Moxy wrote:
> > The while statement shows that the variable phrase is null. However
> > the if statements that follow return true because 3 table rows are
> > created on my page.
> > value="^^no^^" name="logo" value="296.06" name="part_sell_price"
> > value="" name="phrase" value="script" name="font_type" value="386"
> > name="thread_color" value="^^no^^" name="nomex" value="Next >>"
> > name="Submit"
>
> > > > session_start();
> > foreach ($_POST as $key => $value) {
> > $_SESSION[$key] = $value;
> > }
>
> > while (list($name, $value) = each($HTTP_POST_VARS))
>
> please use the same construct as before (foreach($_POST as...)), as
> relying on $HTTP_POST_VARS is hopelessly outdated.
>
> > {
> > echo "value=\"$value\" name=\"$name\"\n";
> > }
>
> Which will show you nothing about the NULL status. NULL is a strange
> beast, an empty string ('') or false will also print nothing to your
> screen, doesn't mean it is NULL. All values arrived by a POST are a string
> by default, and a string cannot be NULL, it can be empty though, not the
> same thing. NULL is actually a type of it's own (next to strings,
> booleans, integers, floats etc.).
>
> --
> Rik Wasmus- Hide quoted text -
>
> - Show quoted text -

Well, I concluded that empty() solved my problem! Thank for the advice
on (foreach($_POST as...)) too! This has been an adventure.

cheers!